import {data as difficultData} from "../../../../xlsx/custom/difficult";
import {data as utilPoolData} from "../../../../xlsx/custom/heroPool";
import {data as attackMonsterData} from "../../../../xlsx/custom/attack_monster";
import {data as skillData} from "../../../../xlsx/base/skill";
import {data as skill1Data} from "../../../../xlsx/base/skill1";
import {data as skill2Data} from "../../../../xlsx/base/skill2";
import {data as skill3Data} from "../../../../xlsx/base/skill3";
import {data as skill4Data} from "../../../../xlsx/base/skill4";
import {data as skill5Data} from "../../../../xlsx/base/skill5";
import {data as skill6Data} from "../../../../xlsx/base/skill6";
import {data as abilityEffectData} from "../../../../xlsx/custom/abilityeffect";
import {data as unitData} from "../../../../xlsx/base/unit";
import {data as rewardItemData} from "../../../../xlsx/custom/reward_item";
import {data as rewardHard1ItemData} from "../../../../xlsx/custom/hard1_reward_item";
import {data as rewardHard2ItemData} from "../../../../xlsx/custom/hard2_reward_item";
import {data as rewardHard3ItemData} from "../../../../xlsx/custom/hard3_reward_item";
import {data as rewardHard4ItemData} from "../../../../xlsx/custom/hard4_reward_item";
import {data as rewardHard5ItemData} from "../../../../xlsx/custom/hard5_reward_item";
import {data as rewardHard6ItemData} from "../../../../xlsx/custom/hard6_reward_item";
import {data as rewardHard7ItemData} from "../../../../xlsx/custom/hard7_reward_item";
import {data as rewardHard8ItemData} from "../../../../xlsx/custom/hard8_reward_item";
import {data as affixData} from "../../../../xlsx/custom/affix";
import {data as rewardGroup} from "../../../../xlsx/custom/reward_group";
import {data as conditionData} from "../../../../xlsx/custom/condition";
import {data as transData} from "../../../../xlsx/custom/tp";
import {data as taskData} from "../../../../xlsx/custom/task";
import {data as itemData} from "../../../../xlsx/base/item";
import {data as generateData} from "../../../../xlsx/custom/generate";
import {data as autocastData} from "../../../../xlsx/custom/autocast";
import {data as pathData} from "../../../../xlsx/custom/path";
import {data as achievementData} from "../../../../xlsx/custom/achievement";
import {data as inputData} from "../../../../xlsx/custom/input";
import {data as timeRewardData} from "../../../../xlsx/custom/time_reward";
import {data as mixData} from "../../../../xlsx/custom/mix";
import {data as talentPoolData} from "../../../../xlsx/custom/talentPool";
import {data as combinationData} from "../../../../xlsx/custom/combination";
import {data as petData} from "../../../../xlsx/custom/pet";
import {data as testData} from "../../../../xlsx/custom/test";
import {data as handBookData} from "../../../../xlsx/custom/atlas";
import {data as attrData} from "../../../../xlsx/custom/attribute";
import {data as appearanceData} from "../../../../xlsx/custom/appearance";
import {data as integralMallData} from "../../../../xlsx/custom/integralMall";
import {data as resourceData} from "../../../../xlsx/custom/resources";
import {
    AbilityData,
    AbilityEffectData,
    AbilityFamilyHotKey,
    AchievementData,
    AffixData,
    AppearanceData,
    AttackMonsterData,
    AttrData,
    AutocastDataData,
    CombinationData,
    ConditionData,
    DifficultData,
    GenerateData,
    HandBookData,
    InputData,
    IntegralMallData,
    ItemData,
    MixData,
    PathData,
    PetData,
    ResourceData,
    RewardGroupData,
    RewardItemData,
    TalentPoolData,
    TaskData,
    TestData,
    TimeRewardData,
    TransData,
    UnitData,
    UnitPoolData
} from "./DataModel";
import {Logger} from "../apiModel/config/Logger";
import {CodeUtil} from "../codeAdapter/CodeUtil";
import Configer from "../apiModel/config/Configer";
import {FinalKey} from "../../constant/FinalConstant";

// 获取配置文件的util类
export class DataRouter {

    // 缓存区，excel转换出来的数组结构在一些情况下不容易遍历，影响性能，在这里可以通过将数组保存成map结构，用空间换取时间
    // 技能效果与技能映射   <效果id, 技能id>
    private static effectId_abilityIds_Mapping: { [key: string]: string[] } = {};
    // 技能效果id与技能效果映射   <效果id, 效果>
    private static effectId_effectData_Mapping: { [key: string]: AbilityEffectData } = {};
    // 技能家族和技能id的映射 <HotKey，技能id>   一维是家族等级  二维是对应热键对应的技能
    private static familyId_abilityIds_Mapping: { [key: string]: AbilityFamilyHotKey[] } = {};
    // 物品家族和物品id的映射 <HotKey，技能id>   一维是家族等级  二维是对应热键对应的物品id
    private static familyId_itemIds_Mapping: { [key: string]: string[] } = {};
    // 技能id和技能的映射 <技能id，abilityData>
    private static abilityId_abilityData_Mapping: { [key: string]: AbilityData } = {};
    // 单位id与单位属性映射
    private static unitId_unitData_Mapping:  { [key: string]: UnitData } = {};
    // 单位家族和单位id的映射 <HotKey，技能id>   一维是家族等级
    private static familyId_unitIds_Mapping: { [key: string]: string[] } = {};
    // rewardId与rewardGroupData映射
    private static rewardGroupId_RewardGroupData_Mapping: { [key: string]: RewardGroupData[] } = {};
    // groupId与item映射
    private static rewardGroupId_rewardItemData_Mapping: { [key: string]: RewardItemData[] } = {};
    // rewardItemId与item映射
    private static rewardItemId_rewardItemData_Mapping: { [key: string]: RewardItemData } = {};
    // affixId与affixData映射
    private static affixId_affixDatas_Mapping: { [key: string]: AffixData } = {};
    // affixGroupId与affixData映射
    private static affixGroupId_affixDatas_Mapping: { [key: string]: AffixData[] } = {};
    // 传送表起始区域名与transData映射
    private static transStart_transData_Mapping: { [key: string]: TransData } = {};
    // 传送表id与transData映射
    private static transId_transData_Mapping: { [key: string]: TransData } = {};
    // 传送起始点与transData映射
    private static start_transData_Mapping: { [key: string]: TransData } = {};
    // 条件表id与conditionData映射
    private static conditionId_conditionData_Mapping: { [key: string]: ConditionData[] } = {};
    // taskId与taskData映射
    private static taskId_taskData_Mapping: { [key: string]: TaskData } = {};
    // unitId与monsterData的映射
    private static unitId_generateData_Mapping: { [key: string]: GenerateData } = {};

    // unitId与PetData的映射
    private static unitId_petData_Mapping: { [key: string]: PetData } = {};


    // 使用物品与物品Data的映射 <物品id，物品Data>
    private static itemId_itemData_Mapping: { [key: string]: ItemData } = {};

    // 装备品质与装备Id的映射 <装备id，装备效果>
    private static goodQuality_goodId_Mapping: string[][] = [];

    // bossId与bossAIData的映射 <单位id，BossAIData>
    // private static bossId_bossAIData_Mapping: Map<string, BossAIData> = new Map<string, BossAIData>();
    // pathId与pathData的映射 <pathId，pathData>
    private static pathId_PathData_Mapping: { [key: string]: PathData } = {};
    // achievementId与achievementData的映射 <achievementId，achievementData>
    private static achievementId_AchievementData_Mapping: { [key: string]: AchievementData } = {};
    // effectId与achievementIds的映射 <effectId，achievementIds>
    private static effectId_achievementIds_Mapping: { [key: string]: string[] } = {};

    // monsterId与monsterData的映射 <monsterId，monsterData>
    private static generateId_generateData_Mapping: { [key: string]: GenerateData } = {};

    // itemId与mixData的映射 <itemId，mixData>
    private static itemId_mixData_Mapping: { [key: string]: MixData[] } = {};
    // mixId与mixData的映射 <mixId，mixData>
    private static mixId_mixData_Mapping: { [key: string]: MixData } = {};
    // CombinationId与CombinationData的映射 <CombinationId，CombinationData>
    private static combinationId_combinationData_Mapping: { [key: string]: CombinationData } = {};
    // itemId与CombinationData的映射 <itemId，CombinationDatas>
    private static itemId_combinationData_Mapping: { [key: string]: CombinationData[] } = {};

    // 单位id与图鉴Id映射
    private static unitId_handBookData_Mapping: { [key: string]: HandBookData } = {};
    private static handBookId_handBookData_Mapping: { [key: string]: HandBookData } = {};

    // 外观id与外观data
    private static appearanceId_appearanceData_Mapping: { [key: string]: AppearanceData } = {};

    // 属性ID与属性表
    private static attrId_attrData_Mapping: { [key: string]: AttrData } = {};

    // 资源ID与资源表
    private static resourceId_resourceData_Mapping: { [key: string]: ResourceData } = {};


    static init = () => {
        // 初始化技能效果映射
        const abilityDatas = DataRouter.getAbilityDatas();
        const ability1Datas = DataRouter.getAbility1Datas();
        abilityDatas.push(...ability1Datas);
        const ability2Datas = DataRouter.getAbility2Datas();
        abilityDatas.push(...ability2Datas);
        const ability3Datas = DataRouter.getAbility3Datas();
        abilityDatas.push(...ability3Datas);
        const ability4Datas = DataRouter.getAbility4Datas();
        abilityDatas.push(...ability4Datas);
        const ability5Datas = DataRouter.getAbility5Datas();
        abilityDatas.push(...ability5Datas);
        const ability6Datas = DataRouter.getAbility6Datas();
        abilityDatas.push(...ability6Datas);
        const abilityInitFun = (abilityDatas: AbilityData[]) => {
            for (let i = 0; i < abilityDatas.length; i ++) {
                const abilityData = abilityDatas[i];
                const id = abilityData.id;
                const effectIds = abilityData.effects;
                const familyId = abilityData.family_tpye;
                DataRouter.abilityId_abilityData_Mapping[id] = abilityData;
                let idArr = DataRouter.familyId_abilityIds_Mapping[familyId];
                const family_level = abilityData.family_level;
                // todo 【需要被回退】 用key
                const hotKey = abilityData.Hotkey
                if (idArr) {
                } else {
                    idArr = [];
                }
                if (family_level) {
                    let abilityFamilyHotKey = idArr[family_level];
                    if (abilityFamilyHotKey) {
                    } else {
                        abilityFamilyHotKey = { Q: undefined, W: undefined, E: undefined, R: undefined, T: undefined, Y: undefined, def: undefined };
                        idArr[family_level] = abilityFamilyHotKey;
                    }
                    if (hotKey) {
                        abilityFamilyHotKey[hotKey] = id;
                    } else {
                        abilityFamilyHotKey.def = id;
                    }
                }
                if (id && familyId) {
                    DataRouter.familyId_abilityIds_Mapping[familyId] = idArr;
                } else {
                    if (familyId) {
                        Logger.toastError(`第${i + 1}个技能缺少ID`);
                    } else if (id) {
                        // SysToastUtil.toastError(`技能${id}未设置快捷健`);
                    }
                }
                let effectIdArr = [];
                if (effectIds && id) {
                    effectIdArr = CodeUtil.getArrBySplit(effectIds)
                    for (let effectIdIndex = 0; effectIdIndex < effectIdArr.length; effectIdIndex += 1) {
                        const effectId = effectIdArr[effectIdIndex];
                        let abilityIds = DataRouter.effectId_abilityIds_Mapping[effectId];
                        if (abilityIds) {
                            abilityIds.push(id);
                        } else {
                            abilityIds = [id];
                        }
                        DataRouter.effectId_abilityIds_Mapping[effectId] = abilityIds;
                    }
                }
            }
        }
        abilityInitFun(abilityDatas);

        Logger.toastSys(`绑定了效果的技能数:${DataRouter.effectId_abilityIds_Mapping.size}`);
        // 初始化单位id与unitData映射
        const unitDatas = DataRouter.getUnitDatas();
        for (let i = 0; i < unitDatas.length; i  ++) {
            const unitData = unitDatas[i];
            const unitId = unitData.id;


            const familyId = unitData.family_tpye;
            let idArr = DataRouter.familyId_unitIds_Mapping[familyId];
            const family_level = unitData.family_level;

            if (idArr) {
            } else {
                idArr = [];
            }

            if (family_level && family_level >= 0) {
                idArr[family_level] = unitId;
            } else {
                idArr[0] = unitId;
            }
            if (unitId && familyId) {
                DataRouter.familyId_unitIds_Mapping[familyId] = idArr;
            } else {
                if (familyId) {
                    Logger.toastError(`第${i + 1}个单位缺少ID`);
                } else if (unitId) {
                    // SysToastUtil.toastError(`技能${id}未设置快捷健`);
                }
            }
            if (unitId) {
                DataRouter.unitId_unitData_Mapping[unitId] = unitData;
            } else {
                Logger.toastError(`第${i + 1}项单位绑定了掉落物品，但本身没有设定ID`);
            }
        }
        Logger.toastSys(`绑定了掉落的单位数:${DataRouter.unitId_unitData_Mapping.size}`);
        // 初始化rewardId与rewardData映射
        const rewardGroupDatas = DataRouter.getRewardGroupDatas();
        for (let i = 0; i < rewardGroupDatas.length; i  ++) {
            const rewardGroupData = rewardGroupDatas[i];
            const rewardId = rewardGroupData.rewardId;
            let arr = DataRouter.rewardGroupId_RewardGroupData_Mapping[rewardId];
            if (arr) {
                arr.push(rewardGroupData);
            } else {
                arr = [rewardGroupData];
            }
            if (rewardId) {
                DataRouter.rewardGroupId_RewardGroupData_Mapping[rewardId] = arr;
            } else {
                Logger.toastError(`掉落表第${i + 1}项没有设定ID`);
            }
        }
        // Logger.toastSys(`掉落表数量:${DataRouter.rewardGroupId_RewardGroupData_Mapping.size}`);
        // 初始化groupId与dropGroup映射
        const groups = DataRouter.getRewardItemDatas();
        const itemHard1Datas = DataRouter.getRewardHard1ItemDatas();
        const itemHard2Datas = DataRouter.getRewardHard2ItemDatas();
        const itemHard3Datas = DataRouter.getRewardHard3ItemDatas();
        const itemHard4Datas = DataRouter.getRewardHard4ItemDatas();
        const itemHard5Datas = DataRouter.getRewardHard5ItemDatas();
        const itemHard6Datas = DataRouter.getRewardHard6ItemDatas();
        const itemHard7Datas = DataRouter.getRewardHard7ItemDatas();
        const itemHard8Datas = DataRouter.getRewardHard8ItemDatas();
        const groupInitFun = (rewardItems: RewardItemData[]) => {
            for (let i = 0; i < rewardItems.length; i  ++) {
                const groupData = rewardItems[i];
                const groupId = groupData.group_Id;
                const itemId = groupData.id;
                if (itemId) {
                    DataRouter.rewardItemId_rewardItemData_Mapping[itemId] = groupData;
                } else {
                    Logger.toastError(`掉落组第${i + 1}项没有设定ID`);
                }
                let arr = DataRouter.rewardGroupId_rewardItemData_Mapping[groupId];
                if (arr) {
                    arr.push(groupData);
                } else {
                    arr = [groupData];
                }
                if (groupId) {
                    DataRouter.rewardGroupId_rewardItemData_Mapping[groupId] = arr;
                } else {
                    Logger.toastError(`掉落组第${i + 1}项没有设定掉落ID`);
                }
            }
        }
        groupInitFun(groups);
        groupInitFun(itemHard1Datas);
        groupInitFun(itemHard2Datas);
        groupInitFun(itemHard3Datas);
        groupInitFun(itemHard4Datas);
        groupInitFun(itemHard5Datas);
        groupInitFun(itemHard6Datas);
        groupInitFun(itemHard7Datas);
        groupInitFun(itemHard8Datas);

        // 权重算几率排序
        // DataRouter.rewardGroupId_rewardItemData_Mapping.forEach(
        //     (value, key, map) => {
        //         let sum = 0;
        //         value.forEach(
        //             (value, index, array) => {
        //                 const weight = value.weight;
        //                 sum = sum + weight;
        //             }
        //         )
        //         value.forEach(
        //             (value, index, array) => {
        //                 const currentNum = value.weight;
        //                 const probability = (currentNum  * 100) / sum;
        //                 value.probability = MathUtil.toFixed(probability, 2);
        //             }
        //         )
        //         value?.sort(
        //             (a: RewardItemData, b: RewardItemData) => {
        //                 if (a.probability > b.probability) {
        //                     return 1
        //                 }
        //                 return 0;
        //             }
        //         )
        //     }
        // )
        // Logger.toastSys(`掉落组数量:${DataRouter.rewardGroupId_rewardItemData_Mapping.size}`);
        Logger.toastSys(`权重从大到小排序`);
        // 初始化groupId与dropGroup映射
        const affixDatas = DataRouter.getAffixDatas();
        for (let i = 0; i < affixDatas.length; i  ++) {
            const affixData = affixDatas[i];
            const affixId = affixData.id;
            const affixGroupId = affixData.group;
            DataRouter.affixId_affixDatas_Mapping[affixId] = affixData;
            let arr = DataRouter.affixGroupId_affixDatas_Mapping[affixGroupId];
            if (arr) {
                arr.push(affixData);
            } else {
                arr = [affixData];
            }
            if (affixGroupId) {
                DataRouter.affixGroupId_affixDatas_Mapping[affixGroupId] = arr;
            } else {
                Logger.toastError(`词缀表第${i + 1}项没有设定词缀组`);
            }
        }
        // 词缀算几率排序
        CodeUtil.mapObj(DataRouter.affixGroupId_affixDatas_Mapping, (key, value) => {
            let sum = 0;
            value.forEach(
                (value, index, array) => {
                    const weight = value.weight;
                    sum = sum + weight;
                }
            )
            value.forEach(
                (value, index, array) => {
                    const currentNum = value.weight;
                    const probability = (currentNum  * 100) / sum;
                    // const rand = Math.ceil(probability);
                    value.probability = probability;
                }
            )
        })
        // Logger.toastSys(`词缀表数量:${DataRouter.affixId_affixDatas_Mapping.size}`);
        Logger.toastSys(`权重从大到小排序`);
        // 初始化传送入口与transData映射
        const transDatas = DataRouter.getTransDatas();
        for (let i = 0; i < transDatas.length; i  ++) {
            const transData = transDatas[i];
            const start = transData.tp_start;
            const id = transData.id;
            if (id) {
                DataRouter.transId_transData_Mapping[id] = transData;
                if (start) {
                    DataRouter.start_transData_Mapping[start] = transData;
                }
            } else {
                Logger.toastError(`传送表第${i + 1}项没有设置ID`);
            }
            if (start) {
                DataRouter.transStart_transData_Mapping[start] = transData;
            }
        }
        // Logger.toastSys(`传送组数量:${DataRouter.transStart_transData_Mapping.size}`);
        // 条件表id与conditionData映射
        const conditionDatas = DataRouter.getConditionDatas();
        for (let i = 0; i < conditionDatas.length; i  ++) {
            const conditionData = conditionDatas[i];
            const conditionId = conditionData.conditionId;
            if (conditionId) {
                let arr = DataRouter.conditionId_conditionData_Mapping[conditionId];
                if (arr) {
                    arr.push(conditionData);
                } else {
                    arr = [conditionData];
                    DataRouter.conditionId_conditionData_Mapping[conditionId] = arr;
                }
            } else {
                Logger.toastError(`条件表第${i + 1}项没有设置ID`);
            }
        }
        // Logger.toastSys(`条件组数量:${DataRouter.conditionId_conditionData_Mapping.size}`);
        // 物品id与taskId映射
        // taskId与taskData映射
        const taskDatas = DataRouter.getTaskDatas();
        for (let i = 0; i < taskDatas.length; i  ++) {
            const taskData = taskDatas[i];
            const taskId = taskData.id;
            if (taskId) {
                DataRouter.taskId_taskData_Mapping[taskId] = taskData;
            } else {
                Logger.toastError(`任务表第${i + 1}项没有设置任务Id`);
            }
        }

        const attrDatas = DataRouter.getAttrDatas();
        for (let i = 0; i < attrDatas.length; i++) {
            const attrData = attrDatas[i];
            const id = attrData.id;
            DataRouter.attrId_attrData_Mapping[id] = attrData;
        }

        const resourceDatas = DataRouter.getResourceDatas();
        for (let i = 0; i < resourceDatas.length; i++) {
            const resourceData = resourceDatas[i];
            const id = resourceData.id;
            DataRouter.resourceId_resourceData_Mapping[id] = resourceData;
        }

        let maxQuality = 0;
        const itemDatas = DataRouter.getItemDatas();
        for (let i = 0; i < itemDatas.length; i  ++) {
            const itemData = itemDatas[i];
            const itemId = itemData.id;
            const type = itemData.item_type;
            const quality = itemData.quality;
            const des = itemData.Description;
            const tip = itemData.Ubertip;
            const attrId = itemData.attrId;

            const replaceFun = (attrStr: string): number => {
                const attrData = DataRouter.attrId_attrData_Mapping[attrId];
                if (attrStr) {
                    if (attrData[attrStr]) {
                        return attrData[attrStr];
                    }
                }
                return 0;
            }

            // const newDes = CodeUtil.replaceAttrStr(des, replaceFun);
            // const newTip = CodeUtil.replaceAttrStr(tip, replaceFun);
            // if (newDes) {
            //     // itemData.Description = newDes;
            //     GlobalModel.setItemDescription(itemId, newDes)
            // }
            // if (newTip) {
            //     // itemData.Ubertip = newTip;
            //     GlobalModel.setItemUbertip(itemId, newTip)
            // }

            if (type) {
                if (itemId) {
                    DataRouter.itemId_itemData_Mapping[itemId] = itemData;

                    if (quality && quality >= 0) {
                        let arr = DataRouter.goodQuality_goodId_Mapping[quality];
                        if (arr) {
                            arr.push(itemId);
                        } else {
                            DataRouter.goodQuality_goodId_Mapping[quality] = [itemId];
                        }
                        if (quality > maxQuality) {
                            maxQuality = quality;
                        }
                    }
                    const familyId = itemData.family_tpye;
                    if (familyId) {
                        let idArr = DataRouter.familyId_itemIds_Mapping[familyId];
                        const family_level = itemData.family_level;

                        if (idArr) {
                        } else {
                            idArr = [];
                        }

                        if (family_level && family_level >= 0) {
                            idArr[family_level] = itemId;
                        } else {
                            idArr[0] = itemId;
                        }
                        DataRouter.familyId_itemIds_Mapping[familyId] = idArr;
                    }

                } else {
                    Logger.toastError(`物品表第${i + 1}项没有设置物品Id`);
                }
            }
        }
        // Logger.toastSys(`物品表数量:${DataRouter.itemId_itemData_Mapping.size}`);
        // unitid与monsterData映射
        const generateDatas = DataRouter.getGenerateDatas();
        for (let i = 0; i < generateDatas.length; i++) {
            const generateData = generateDatas[i];
            const monsterId = generateData.monster_id;
            const id = generateData.id;
            DataRouter.generateId_generateData_Mapping[id] = generateData;
            if (monsterId) {
                DataRouter.unitId_generateData_Mapping[monsterId] = generateData;
            } else {
                Logger.toastWarn(`刷怪表第${i + 1}项没有设置怪物ID`);
            }
        }
        // Logger.toastSys(`刷怪表数量:${DataRouter.unitId_generateData_Mapping.size}`);

        // const petDatas = DataRouter.getPetDatas();
        // for (let i = 0; i < petDatas.length; i++) {
        //     const petData = petDatas[i];
        //     const catch_id = petData.catch_id;
        //     DataRouter.unitId_petData_Mapping.set(catch_id, petData);
        // }
        // Logger.toastSys(`宠物表数量:${DataRouter.unitId_petData_Mapping.size}`);


        // Logger.toastSys(`物品表数量:${DataRouter.goodId_goodData_Mapping.size}`);
        // pathId与pathData映射
        const pathDatas = DataRouter.getPathDatas();
        for (let i = 0; i < pathDatas.length; i  ++) {
            const pathData = pathDatas[i];
            const pathId = pathData.id;
            if (pathId) {
                DataRouter.pathId_PathData_Mapping[pathId] = pathData;
            } else {
                Logger.toastError(`路径表第${i + 1}项没有设置路径ID`);
            }
        }
        const achievementDatas = DataRouter.getAchievementDatas();
        for (let i = 0; i < achievementDatas.length; i++) {
            const achievementData = achievementDatas[i];
            const achievementId = achievementData.id;
            if (achievementId) {
                DataRouter.achievementId_AchievementData_Mapping[achievementId] = achievementData;
            } else {
                Logger.toastError(`成就表第${i + 1}项没有设置成就Id`);
            }
            const effectId = achievementData.effects;
            const effectArr = CodeUtil.getArrBySplit(effectId);
            effectArr.forEach(
                (value, index, array) => {
                    const achievementIds = DataRouter.effectId_achievementIds_Mapping[value];
                    if (achievementIds) {
                        achievementIds.push(achievementId);
                    } else {
                        const achievementIds: string[] = [ achievementId ];
                        DataRouter.effectId_achievementIds_Mapping[value] = achievementIds;
                    }

                }
            )
        }
        // Logger.toastSys(`成就表数量:${DataRouter.achievementId_AchievementData_Mapping.size}`);
        const mixDatas = DataRouter.getMixDatas();
        for (let i = 0; i < mixDatas.length; i++) {
            const mixData = mixDatas[i];
            const id = mixData.id;
            const itemStrs = mixData.material_id;
            const itemArr = CodeUtil.getArrBySplit(itemStrs)
            DataRouter.mixId_mixData_Mapping[id] = mixData;
            for (let i = 0; i < itemArr.length; i++) {
                const itemId = itemArr[i];
                if (!CodeUtil.isNullOrZero(itemId)) {
                    const mixArr = DataRouter.itemId_mixData_Mapping[itemId];
                    if (mixArr && mixArr.length > 0) {
                        mixArr.push(mixData);
                    } else {
                        const newArr: MixData[] = [mixData];
                        DataRouter.itemId_mixData_Mapping[itemId] = newArr;
                    }
                }
            }
        }
        // Logger.toastSys(`合成表数量:${DataRouter.itemId_mixData_Mapping.size}`);

        const combinationDatas = DataRouter.getCombinationDatas();
        for (let i = 0; i < combinationDatas.length; i++) {
            const combinationData = combinationDatas[i];
            const id = combinationData.id;
            const itemStrs = combinationData.material_id;
            const itemArr = CodeUtil.getArrBySplit(itemStrs)
            DataRouter.combinationId_combinationData_Mapping[id] = combinationData;
            for (let i = 0; i < itemArr.length; i++) {
                const itemId = itemArr[i];
                if (!CodeUtil.isNullOrZero(itemId)) {
                    const mixArr = DataRouter.itemId_combinationData_Mapping[itemId];
                    if (mixArr && mixArr.length > 0) {
                        mixArr.push(combinationData);
                    } else {
                        const newArr: CombinationData[] = [combinationData];
                        DataRouter.itemId_combinationData_Mapping[itemId] = newArr;
                    }
                }
            }
        }
        // Logger.toastSys(`羁绊表数量:${DataRouter.combinationId_combinationData_Mapping.size}`);

        const handBookDatas = DataRouter.getHandBookDatas();
        for (let i = 0; i < handBookDatas.length; i++) {
            const handBookData = handBookDatas[i];
            const unitId = handBookData.family_tpye;
            const id = handBookData.id;
            DataRouter.unitId_handBookData_Mapping[unitId] = handBookData;
            DataRouter.handBookId_handBookData_Mapping[id] = handBookData;
        }
        // Logger.toastSys(`图鉴表数量:${DataRouter.unitId_handBookData_Mapping.size}`);

        const appearanceDatas = DataRouter.getAppearanceDatas();
        for (let i = 0; i < appearanceDatas.length; i++) {
            const appearanceData = appearanceDatas[i];
            const id = appearanceData.id;
            DataRouter.appearanceId_appearanceData_Mapping[id] = appearanceData;
        }
        // Logger.toastSys(`外观表数量:${DataRouter.appearanceId_appearanceData_Mapping.size}`);

        // Logger.toastSys(`外观表数量:${DataRouter.appearanceId_appearanceData_Mapping.size}`);
    }
    static getHandBookDataByUnitId(unitId: string): HandBookData | undefined {
        const handBookData = DataRouter.unitId_handBookData_Mapping[unitId];
        return handBookData;
    }
    static getAppearanceDataByAppearanceId(appearance: string): AppearanceData | undefined  {
        const appearanceData = DataRouter.appearanceId_appearanceData_Mapping[appearance];
        return appearanceData;
    }
    static getHandBookDataByHandBookId(handBookId: string): HandBookData | undefined  {
        const handBookData = DataRouter.handBookId_handBookData_Mapping[handBookId];
        return handBookData;
    }

    static getResourceDataByResourceId(resourceId: string): ResourceData | undefined  {
        const resourceData = DataRouter.resourceId_resourceData_Mapping[resourceId];
        return resourceData;
    }

    static getAbilityIdsByEffectId(effectId: string): string[] | undefined  {
        const abilityId = DataRouter.effectId_abilityIds_Mapping[effectId];
        return abilityId;
    }

    static getAbilityDataById(id: string): AbilityData | undefined {
        const abilityData = DataRouter.abilityId_abilityData_Mapping[id];
        return abilityData;
    }

    static getEffectByEffectId(effectId: string): AbilityEffectData | undefined {
        const effectData = DataRouter.effectId_effectData_Mapping[effectId];
        return effectData;
    }
    static setEffectByEffectId(effectId: string, effect: AbilityEffectData) {
        DataRouter.effectId_effectData_Mapping[effectId] = effect;
    }
    static getUnitDataByUnitId(unitId: string): UnitData | undefined {
        const unitData = DataRouter.unitId_unitData_Mapping[unitId];
        return unitData;
    }
    static getRewardGroupDataByRewardGroupId(rewardGroupId: string): RewardGroupData[] | undefined {
        const rewardData = DataRouter.rewardGroupId_RewardGroupData_Mapping[rewardGroupId];
        return rewardData;
    }
    static getRewardItemsByRewardGroupId(rewardGroupId: string): RewardItemData[] | undefined {
        const groups = DataRouter.rewardGroupId_rewardItemData_Mapping[rewardGroupId];
        return groups;
    }
    static getRewardItemByRewardId(rewardItemId: string): RewardItemData | undefined {
        const groups = DataRouter.rewardItemId_rewardItemData_Mapping[rewardItemId];
        return groups;
    }
    static getAffixDatasByGroupID(groupId: string): AffixData[] | undefined {
        const affixDatas = DataRouter.affixGroupId_affixDatas_Mapping[groupId];
        return affixDatas;
    }

    static getAffixDatasByAffixID(affixId: string): AffixData | undefined {
        const affixData = DataRouter.affixId_affixDatas_Mapping[affixId];
        return affixData;
    }
    static getAbilityIdsByFamilyId(familyId: string): AbilityFamilyHotKey[] | undefined {
        const abilityIds = DataRouter.familyId_abilityIds_Mapping[familyId];
        return abilityIds;
    }
    static getItemIdsByFamilyId(familyId: string): string[] | undefined {
        const itemIds = DataRouter.familyId_itemIds_Mapping[familyId];
        return itemIds;
    }
    static getUnitIdsByFamilyId(familyId: string): string[] | undefined {
        const unitIds = DataRouter.familyId_unitIds_Mapping[familyId];
        return unitIds;
    }
    static getTransDataByTransId(transId: string): TransData | undefined {
        const transData = DataRouter.transId_transData_Mapping[transId];
        return transData;
    }
    static getTransDataByStart(start: string): TransData | undefined {
        const transData = DataRouter.start_transData_Mapping[start];
        return transData;
    }
    static mapAllTransData(callback: (value: TransData, key: string) => void) {
        const transStart_transData_Mapping = DataRouter.transStart_transData_Mapping;
        CodeUtil.mapObj(transStart_transData_Mapping, (key, value) => {
            callback(value, key)
        })
    }
    static getTaskDataByTaskId(taskId: string): TaskData | undefined {
        const taskData = DataRouter.taskId_taskData_Mapping[taskId];
        return taskData;
    }
    static getConditionDataByConditionId(conditionId: string): ConditionData[] | undefined {
        const conditionData = DataRouter.conditionId_conditionData_Mapping[conditionId];
        return conditionData;
    }
    static getItemDataByItemId(itemId: string): ItemData | undefined  {
        const itemData = DataRouter.itemId_itemData_Mapping[itemId];
        return itemData;
    }
    static getAttrDataByAttrId(attrId: string): AttrData | undefined  {
        const attrData = DataRouter.attrId_attrData_Mapping[attrId];
        return attrData;
    }
    static getGoodIdsByQuality(quality: number): string[] | undefined  {
        const ids = DataRouter.goodQuality_goodId_Mapping[quality];
        return ids;
    }
    static getPathDataByPathId(pathId: string): PathData | undefined  {
        const pathData = DataRouter.pathId_PathData_Mapping[pathId];
        return pathData;
    }
    static getAchievementDataByAchievementId(achievementId: string): AchievementData | undefined  {
        const achievementData = DataRouter.achievementId_AchievementData_Mapping[achievementId];
        return achievementData;
    }
    static getAchievementIdsByEffectId(effectId: string): string[] | undefined  {
        const achievementIds = DataRouter.effectId_achievementIds_Mapping[effectId];
        return achievementIds;
    }
    static getGenerateDataByGenerateId(monsterId: string): GenerateData | undefined  {
        const monsterData = DataRouter.generateId_generateData_Mapping[monsterId];
        return monsterData;
    }
    static getMixDatasByItemId(itemId: string): MixData[] | undefined  {
        const mixDatas = DataRouter.itemId_mixData_Mapping[itemId];
        return mixDatas;
    }
    static getMixDatasByMixId(mixId: string): MixData | undefined  {
        const mixData = DataRouter.mixId_mixData_Mapping[mixId]
        return mixData;
    }
    static getCombinationDataByCombinationId(combinationId: string): CombinationData | undefined  {
        const combinationData = DataRouter.combinationId_combinationData_Mapping[combinationId];
        return combinationData;
    }
    static getCombinationDatasByItemId(itemId: string): CombinationData[] | undefined  {
        const combinationData = DataRouter.itemId_combinationData_Mapping[itemId];
        return combinationData;
    }

    static mapAllAbilityData(fun: (abilityData: AbilityData) => void) {
        const abilityDatas = this.getAbilityDatas();
        abilityDatas.forEach(
            (value, index, array) => {
                fun(value)
            }
        )
        const abilityDatas1 = this.getAbility1Datas();
        abilityDatas1.forEach(
            (value, index, array) => {
                fun(value)
            }
        )
        const abilityDatas2 = this.getAbility2Datas();
        abilityDatas2.forEach(
            (value, index, array) => {
                fun(value)
            }
        )
        const abilityDatas3 = this.getAbility3Datas();
        abilityDatas3.forEach(
            (value, index, array) => {
                fun(value)
            }
        )
        const abilityDatas4 = this.getAbility4Datas();
        abilityDatas4.forEach(
            (value, index, array) => {
                fun(value)
            }
        )
    }

    //  ------------------------------------------------------------------------------------------------------------------------------------------------------

    // [{ id: '难度N' }]
    static getDifficultDatas = (): DifficultData[] => {
        const temp = difficultData as DifficultData[]
        return temp;
    }

    // [{ id: 'AOO4' }]
    static getUtilPoolDatas = (): UnitPoolData[] => {
        const temp = utilPoolData as UnitPoolData[]
        return temp;
    }

    // static mapDifficultDatas = (fun: (difficultData: DifficultData) => void) => {
    //     const difficults = DataRouter.getDifficultDatas();
    //     for (let i = 0; i < difficults.length; i ++) {
    //         const difficult = difficults[i];
    //         fun(difficult)
    //     }
    // }
    // // [{ id: 'AOO4' }]
    // static getUtilSRPoolDatas = (): IDData[] => {
    //     const temp = utilSRPoolData as IDData[]
    //     return temp;
    // }
    // // [{ id: 'AOO4' }]
    // static getUtilSSRPoolDatas = (): IDData[] => {
    //     const temp = utilSSRPoolData as IDData[]
    //     return temp;
    // }
    //
    // // [{ id: 'AOO4' }]
    // static getAbilityRPoolDatas = (): IDData[] => {
    //     const temp = abilityRPoolData as IDData[]
    //     return temp;
    // }
    // // [{ id: 'AOO4' }]
    // static getAbilitySRPoolDatas = (): IDData[] => {
    //     const temp = abilitySRPoolData as IDData[]
    //     return temp;
    // }

    // [{
    //      id: 'AOO4';
    //      interval: 30
    // }]
    static getAttackMonsterDatas = (): AttackMonsterData[] => {
        const temp = attackMonsterData as AttackMonsterData[]
        return temp;
    }
    // [{
    //     id: '小试牛刀';
    //     descript: '力量增加100点';
    //     // 力量
    //     strength: 100
    //     // 敏捷
    //     agile: 0;
    //     // 智力
    //     intellect: 0;
    //     // 攻击力
    //     attack: 0;
    //     // 护甲
    //     defense: 0;
    //     // 物理暴击伤害增益
    //     CH_physics_hurt: 0;
    //     // 物理暴击几率
    //     CH_physics_chance: 0;
    //     // 法术暴击伤害增益
    //     CH_spell_hurt: 0;
    //     // 法术暴击几率
    //     CH_spell_chance: 0;
    // }]
    static getAchievementDatas = (): AchievementData[] => {
        const temp = achievementData as AchievementData[]
        return temp;
    }
    static getAbilityDatas = (): AbilityData[] => {
        const temp = skillData as AbilityData[];
        return temp;
    }
    static getAbility1Datas = (): AbilityData[] => {
        const temp = skill1Data as AbilityData[];
        return temp;
    }
    static getAbility2Datas = (): AbilityData[] => {
        const temp = skill2Data as AbilityData[];
        return temp;
    }
    static getAbility3Datas = (): AbilityData[] => {
        const temp = skill3Data as AbilityData[];
        return temp;
    }
    static getAbility4Datas = (): AbilityData[] => {
        const temp = skill4Data as AbilityData[];
        return temp;
    }

    static getAbility5Datas = (): AbilityData[] => {
        const temp = skill5Data as AbilityData[];
        return temp;
    }

    static getAbility6Datas = (): AbilityData[] => {
        const temp = skill6Data as AbilityData[];
        return temp;
    }
    static getAbilityEffectDatas = (): AbilityEffectData[]=> {
        const temp = abilityEffectData as AbilityEffectData[]
        return temp;
    }
    static getUnitDatas = (): UnitData[] => {
        const temp = unitData as UnitData[]
        return temp;
    }
    static getItemDatas = (): ItemData[] => {
        const temp = itemData as ItemData[]
        return temp;
    }
    static getRewardGroupDatas = (): RewardGroupData[] => {
        const temp = rewardGroup as RewardGroupData[]
        return temp;
    }
    static getRewardItemDatas = (): RewardItemData[] => {
        const temp = rewardItemData as RewardItemData[]
        return temp;
    }
    static getRewardHard1ItemDatas = (): RewardItemData[] => {
        const temp = rewardHard1ItemData as RewardItemData[]
        return temp;
    }
    static getRewardHard2ItemDatas = (): RewardItemData[] => {
        const temp = rewardHard2ItemData as RewardItemData[]
        return temp;
    }
    static getRewardHard3ItemDatas = (): RewardItemData[] => {
        const temp = rewardHard3ItemData as RewardItemData[]
        return temp;
    }
    static getRewardHard4ItemDatas = (): RewardItemData[] => {
        const temp = rewardHard4ItemData as RewardItemData[]
        return temp;
    }
    static getRewardHard5ItemDatas = (): RewardItemData[] => {
        const temp = rewardHard5ItemData as RewardItemData[]
        return temp;
    }
    static getRewardHard6ItemDatas = (): RewardItemData[] => {
        const temp = rewardHard6ItemData as RewardItemData[]
        return temp;
    }
    static getRewardHard7ItemDatas = (): RewardItemData[] => {
        const temp = rewardHard7ItemData as RewardItemData[]
        return temp;
    }
    static getRewardHard8ItemDatas = (): RewardItemData[] => {
        const temp = rewardHard8ItemData as RewardItemData[]
        return temp;
    }
    static getAffixDatas = (): AffixData[] => {
        const temp = affixData as AffixData[]
        return temp;
    }
    static getTransDatas = (): TransData[] => {
        const temp = transData as TransData[]
        return temp;
    }
    static getConditionDatas = (): ConditionData[] => {
        const temp = conditionData as ConditionData[]
        return temp;
    }
    static getTaskDatas = (): TaskData[] => {
        const temp = taskData as TaskData[]
        return temp;
    }
    static getGenerateDatas = (): GenerateData[] => {
        const temp = generateData as GenerateData[]
        return temp;
    }
    static getAutocastDatas = (): AutocastDataData[] => {
        const temp = autocastData as AutocastDataData[]
        return temp;
    }
    static getPathDatas = (): PathData[] => {
        const temp = pathData as PathData[]
        return temp;
    }
    static getInputDatas = (): InputData[] => {
        const temp = inputData as InputData[]
        return temp;
    }
    static getTimeRewardDatas = (): TimeRewardData[] => {
        const temp = timeRewardData as TimeRewardData[];
        return temp;
    }
    static getMixDatas = (): MixData[] => {
        const temp = mixData as MixData[]
        return temp;
    }
    static getTalentDatas = (): TalentPoolData[] => {
        const temp = talentPoolData as TalentPoolData[]
        return temp;
    }
    static getCombinationDatas = (): CombinationData[] => {
        const temp = combinationData as CombinationData[]
        return temp;
    }
    static getPetDatas = (): PetData[] => {
        const temp = petData as PetData[]
        return temp;
    }
    static getTestDatas = (): TestData[] => {
        const temp = testData as TestData[]
        return temp;
    }
    static getHandBookDatas = (): HandBookData[] => {
        const temp = handBookData as HandBookData[]
        return temp;
    }
    static getAppearanceDatas = (): AppearanceData[] => {
        const temp = appearanceData as AppearanceData[]
        return temp;
    }
    static getIntegralMallDatas = (): IntegralMallData[] => {
        const temp = integralMallData as IntegralMallData[]
        return temp;
    }

    static getResourceDatas = (): ResourceData[] => {
        const temp = resourceData as ResourceData[]
        return temp;
    }
    static getAttrDatas = (): AttrData[] => {
        const temp = attrData as AttrData[]
        return temp;
    }
}